<template>
	<view class="user">
		<!--头部-->
		<view class="user-section">
			<!--用户信息-->
			<view class="user-info-box">
				<view class="portrait-box" @tap="toLogin()">
					<image class="portrait" :src="userInfo.thumb || '/static/missing-face.png'"></image>
					<view>
						<view class="username">
							{{
								userInfo.name ||
								userInfo.name ||
									'登录/注册'
							}}
						</view>
						<view class="department" v-if="userInfo.jobNumber">工号：{{userInfo.jobNumber}}</view>
						<view class="department" v-if="userInfo.deptName">部门：{{userInfo.deptName}}</view>
						<view class="department" v-if="userInfo.type">员工类型：{{ type[userInfo.type] }}</view>
						<view class="department" v-if="userInfo.isStaff">身份类型：{{ isStaff[userInfo.isStaff] }}</view>
					</view>
				</view>
			</view>

		</view>
		<!-- 个人中心 内容区-->
		<view class="cover-container">
			<image class="arc" src="/static/arc.png"></image>
			<view class="promotion-center baocan">
				<list-cell icon="t-icon-shixinchaxun" navigateType="t-icon-youjiantou"
					@eventClick="navTo(`/pagesMeal/baocan/log`)" title="报餐记录"></list-cell>
				<view class="tj-sction">
					<view class="tj-item" @click="showCode(breakfastOrdered)">
						<view class="bold-num">{{breakfastOrdered}}</view>
						<view>今日早餐</view>
					</view>
					<view class="tj-item" @click="showCode(lunchOrdered)">
						<view class="bold-num">{{lunchOrdered}}</view>
						<view>今日午餐</view>
					</view>
					<view class="tj-item" @click="showCode(dinnerOrdered)">
						<view class="bold-num">{{dinnerOrdered}}</view>
						<view>今日晚餐</view>
					</view>
				</view>
			</view>
			<view class="promotion-center">
				<list-cell icon="t-icon-tongjitu" navigateType="t-icon-youjiantou"
					@eventClick="navTo(`/pagesMeal/baocan/summary`)" title="订餐汇总"></list-cell>
			</view>
			<view class="promotion-center">
				<list-cell icon="t-icon-drxx04" navigateType="t-icon-youjiantou"
					@eventClick="navTo(`/pagesMember/update/password`)" title="修改密码"></list-cell>
			</view>

			<!-- <view class="promotion-center">
				<list-cell icon="t-icon-huiyishi2" navigateType="t-icon-youjiantou"
					@eventClick="navTo(`/pagesConference/huiyi/myreserve`)" title="我的会议室"></list-cell>
			</view> -->
		</view>
		<tabBar selectedIndex="1" selectedTab="0" />
	</view>
</template>

<script>
	import listCell from '@/components/cell/index.vue';
	
	import {
		postFoodDietList, // 获取当天报餐详情
	} from "@/proxy/food/food.api.js";
	
	import {
		getDates, // 获取当天日期
	} from "@/utils/dateTime.js";

	export default {
		components: {
			listCell // 注册 listCell 组件
		},
		data() {
			return {
				userInfo: {} ,// 用于存储用户信息
				type:["未设置","正式","试用","实习"],
				isStaff:["未设置","企业员工","劳务派遣","兼职员工"],
				breakfastOrdered:"0",
				lunchOrdered:"0",
				dinnerOrdered:"0",
			};
		},
		methods: {
			// 登录方法
			toLogin() {
				uni.navigateTo({
					url: '/pagesMember/login/login'
				});
			},
			// 跳转到订餐记录页
			navTo(pages) {
				uni.navigateTo({
					url: pages
				});
			},
			eventClick(){
				this.navTo()
			},
		},
		async mounted() {
			// 获取本地存储的信息
			this.userInfo = uni.getStorageSync("userInfo");
			
			try {
			    const result = await postFoodDietList({
			        name: this.userInfo.name, // 人
					jobNumber: this.userInfo.jobNumber, // 报餐人, // 人
					in:getDates(),
					out:getDates()
			    });
				
			    console.log("报餐任务结果", result);
			    if (result.code == 200 && result.data.length > 0) {
			        // 提交成功后的操作
					const { breakfastOrdered,lunchOrdered,dinnerOrdered } = result.data[0];
					this.breakfastOrdered = breakfastOrdered;
					this.lunchOrdered = lunchOrdered;
					this.dinnerOrdered = dinnerOrdered;
			    }
						
			} catch (err) {
				this.$toast({
					icon: 'none',
					title: '发起失败，请联系管理员！',
					duration: 2000
				});
				console.log(err);
			}
		}
	};
</script>

<style lang="scss" scoped>
	page {
		background-color: #f1f1f1;
	}

	.user {
		.user-section {
			height: 465rpx;
			padding: 100rpx 30rpx 0;
			position: relative;
			background: #0081ff;
			color: #ffffff;
			background-image: url("https://limsapi.gzhbcss.com/static/index_header_1.jpg");
			background-size: cover;
			background-position: center;

			.user-info-box {
				height: 180rpx;
				display: flex;
				align-items: center;
				position: relative;
				z-index: 1;
				justify-content: space-between;

				.portrait-box {
					display: flex;
					align-items: center;

					.portrait {
						width: 130rpx;
						height: 130rpx;
						border: 5rpx solid #fff;
						border-radius: 50%;
					}

					.username {
						font-size: 30rpx;
						color: #fff;
						margin-left: 20rpx;
					}

					button {
						background-color: transparent;
						font-size: 30rpx;
						color: red;
						border: none;
					}

					button::after {
						border: none;
					}
				}
			}

		}

		.cover-container {
			margin-top: -150rpx;
			padding: 0 30rpx 20rpx;
			position: relative;
			background-color: #f8f8f8;

			.arc {
				position: absolute;
				left: 0;
				top: -34rpx;
				width: 100%;
				height: 36rpx;
			}

			.promotion-center {
				background: #fff;
				margin-bottom: 20rpx;

				/*分类列表*/
				.category-list {
					width: 100%;
					padding: 0 0 30rpx 0;
					border-bottom: solid 2rpx #f6f6f6;
					display: flex;
					flex-wrap: wrap;

					.category {
						width: 33.3%;
						margin-top: 50rpx;
						display: flex;
						justify-content: center;
						flex-wrap: wrap;

						.img {
							width: 100%;
							display: flex;
							justify-content: center;

							.iconfont {
								font-size: 30rpx;
							}
						}

						.text {
							width: 100%;
							display: flex;
							justify-content: center;
							font-size: 24rpx;
							color: #3c3c3c;
						}

						.share-btn {
							height: 142rpx;
							text-align: left;
							background: none;
							padding: 0;
							margin: 0;
						}

						.share-btn:after {
							border: none;
							border-radius: none;
						}
					}
				}
			}

			.tj-sction {
				@extend %section;
				display: flex;

				.tj-item {
					@extend %flex-center;
					flex: 1;
					flex-direction: column;
					margin: 30rpx 0;
					font-size: small;
					color: #75787d;
					/*border-right: 2rpx solid rgba(0, 0, 0, 0.2);*/
				}

				/*.tj-item:last-child {*/
				/*border-right: none;*/
				/*}*/
				.num {
					font-size: 30rpx;
				}

				.red {
					color: red;
				}
			}

			.order-section {
				@extend %section;
				padding: 28rpx 0;

				.order-item {
					@extend %flex-center;
					width: 120rpx;
					height: 120rpx;
					border-radius: 10rpx;
					font-size: small;
					color: darkgray;
					position: relative;
				}

				.badge {
					position: absolute;
					top: 0;
					right: 4rpx;
				}

				.iconfont {
					font-size: 48rpx;
				}

				.icon-shouhoutuikuan {
					font-size: 44rpx;
				}
			}
		}
	}

	%flex-center {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	%section {
		justify-content: space-around;
		display: flex;
		align-content: center;
		background: #fff;
		border-radius: 10rpx;
	}

	.baocan {
		.bold-num {
			font-weight: bold;
			font-size: 40rpx;
		}
	}

	.department {
		margin-left: 20rpx;
		font-size: 30rpx;
	}
</style>